package controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sql.UserStoryDao;
import beans.UserStoryBean;

/**
 * Servlet implementation class GetUserStoryData
 */
@WebServlet("/GetUserStoryData")
public class GetUserStoryData extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetUserStoryData() {
        super();
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		UserStoryDao userStoryDao = new UserStoryDao();
		String idAsString = request.getParameter("user-story-id");
		int id = 0;
		if (idAsString != null) {
			id = Integer.parseInt(idAsString);
		}
		try {
			UserStoryBean userStoryBean = userStoryDao.getUserStoryInfo(id);
			PrintWriter out = response.getWriter();
			out.write(userStoryBean.getJson());
		} catch (ClassNotFoundException | SQLException e) {
			e.printStackTrace();
		}
	}

}
